import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/domain/shop/HonourCard.dart';
import 'package:bxultimate/domain/shop/Shop.dart';
import 'package:bxultimate/domain/shop/ShopCategory.dart';
import 'package:bxultimate/domain/shop/ShopDashboard.dart' hide Shop;
import 'package:bxultimate/shared/util/util_http.dart';

class ShopRequest {
  /**
   * 获取商家分类
   */
  static Future<List<ShopCategory>> getShopCategory() async {
    var response = await UtilHttp().get(
      '/business/shopCategory/getAll',
    );
    return response['data']
        .map<ShopCategory>((item) => ShopCategory.fromJson(item))
        .toList();
  }

  static Future<List<Shop>> getShopList(page, size, showType) async {

    var response = await UtilHttp().get(
      '/app/shop/ignoreUrl/getShopList?pageNumber=${page}&pageSize=${size}&showType=${showType}&lat=37.89403&lon=112.57053&areaXzqh=100010',
    );
    return response['data']['records']
        .map<Shop>((item) => Shop.fromJson(item))
        .toList();
  }

  // 分类商家
  static Future<List<Shop>> getShopListByCategory(page, size, category) async {
    var response = await UtilHttp().get(
      '/app/shop/ignoreUrl/getShopList?pageNumber=${page}&pageSize=${size}&showType=category&lat=37.89403&lon=112.57053&areaXzqh=100010&category=${category}',
    );
    return response['data']['records']
        .map<Shop>((item) => Shop.fromJson(item))
        .toList();
  }

  // 商家详情
  static Future<Shop> getShopDetail(id) async {
    var response = await UtilHttp().get(
      '/app/shop/ignoreUrl/${id}',
    );
    return Shop.fromJson(response['data']);
  }


  // 获取我创建的商家
  static Future<ShopDashboard> getMyShop() async {
    var response = await UtilHttp().get(
      '/app/shop/myShop',
    );
    return ShopDashboard.fromJson(response['data']);
  }

  // 更新商家
  static Future<Result> updateShop(data) async {
    var response = await UtilHttp().post(
      '/business/shop/updateShop',
      data:data
    );
    return Result.fromJson(response);
  }

  // 获取荣耀标牌
  static Future<HonourCard> getMyShopElectronIdcard() async {
    var response = await UtilHttp().get(
      '/business/shopElectronIdcard/getMyShopElectronIdcard',
    );
    return HonourCard.fromJson(response['data']);
  }

  // 获取是否有商家
  static Future<Shop?> checkMyShop() async {
    var response = await UtilHttp().get(
      '/app/shop/checkMyShop',
    );
    if(response['data'] == null){
      return null;
    }
    return Shop.fromJson(response['data']);
  }
}
